package bili

import (
	"encoding/json"
	"fmt"
	"os"
	"path"
)

type Bili struct {
}

type vod_bili struct {
	Vod_id       string `json:"vod_id"`
	Vod_name     string `json:"vod_name"`
	Vod_pic      string `json:"vod_pic"`
	Vod_tag      string `json:"vod_tag"`
	Vod_director string `json:"vod_director"`
	Vod_remarks  string `json:"vod_remarks"`
	Vod_content  string `json:"vod_content"`
	Type_name    string `json:"type_name"`

	Vod_play_url string `json:"vod_play_url"`
}

func (bl *Bili) walkdir(g *group, p string) (vods []*vod) {
	vods = make([]*vod, 0, 10)
	bs, err := os.ReadFile(path.Join(p, "__vods.json"))
	if err != nil {
		return
	}
	return bl.parse(g, p, bs, vods)
}

func (bl *Bili) parse(g *group, p string, bs []byte, vods1 []*vod) (vods []*vod) {
	vs := make([]vod_bili, 0)
	err := json.Unmarshal(bs, &vs)
	if err != nil {
		return
	}

	for _, v := range vs {
		fmt.Printf("vs: %v\n", vs)
		fmt.Printf("vs: %v\n", len(vs))
		vi := &vod{
			Group:            g,
			Name:             v.Vod_name,
			Dir:              "",
			InfoJsonPath:     "",
			Pic:              path.Join(p, v.Vod_pic),
			VideoTitleFilter: 0,
		}
		g.Vods = append(g.Vods, vi)
	}

	// type vod struct {
	// 	// homevideo_model.Detail
	// 	Group *group

	// 	Name string // 后备Name, 优先使用 json中的信息
	// 	Dir  string

	// 	InfoJsonPath string // -> info
	// 	Pic          string

	// 	VideoTitleFilter int
	// 	VideoPaths       []*videoInfo
	// }
	return
}
